import user from "@/common/user.js"
import http from "@/common/http.js"

// POST /api/v1/getCommodityList 获取我的机具接口
function getCommodityList(page, startDate, endDate, boundStatus, call) {
	user.getSign(secret => {
		let date = new Date();
		let data = {
			"current": page,
			"size": 20,
			"secret": secret,
			"startDate": startDate, // 格式 2022-04-06
			"endDate": endDate, // 格式 2022-04-06
			"boundStatus": boundStatus, // 格式 2022-04-06
			"userId": user.getUserId()
		}

		http.request({
			url: '/api/v1/getCommodityList',
			data: data,
			success: ret => {
				call(ret);
			},
			fail: ret => {
				console.log(ret);
				uni.showToast({
					icon: 'none',
					title: '获取机具信息失败'
				})
			}
		})

	})


}

function bound(no,call) {
	http.request({
		url: '/api/v1/bound',
		data: {
			"no": no,
			"userId": user.getUserId()
		},
		success: ret => {
			call();
		},
		fail: ret => {
			uni.showToast({
				icon: 'none',
				title: ret.errorMessage
			})
		}
	})
}

function unBound(no,call) {
	http.request({
		url: '/api/v1/unBound',
		data: {
			"no": no,
			"userId": user.getUserId()
		},
		success: ret => {
			call();
		},
		fail: ret => {
			uni.showToast({
				icon: 'none',
				title: ret.errorMessage
			})
		}
	})
}

export default {
	getCommodityList: getCommodityList,
	bound: bound,
	unBound: unBound,
}
